<!-- 2017-12-7 14:56:03 | 修改 木遥（微信:  http://marsgis.cn/weixin.html ） -->
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <!-- 标题及搜索关键字 -->
    <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
    />

    <link rel="shortcut icon" type="image/x-icon" href="http://mars3d.cn/favicon.ico" />
    <title>行人漫游 | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

    <script
      type="text/javascript"
      src="../lib/include-lib.js"
      libpath="../lib/"
      include="jquery,font-awesome,bootstrap,bootstrap-checkbox,jquery.range,layer,haoutil,turf,mars3d"
    ></script>

    <link href="css/style.css" rel="stylesheet" />
    <link href="css/divGraphic.css" rel="stylesheet" />
    <style>
      .mp_table {
        width: 100%;
        border: #cde1de 1px solid;
        font-size: 12px;
        border-collapse: collapse;
        border-spacing: 0;
      }

      .mp_table tr td {
        padding: 5px 5px;
        text-align: left;
        border: #cde1de 1px solid;
      }

      .mp_table tr td:first-child {
        border-left: none;
      }

      .nametd {
        width: 40%;
      }

      .mp_head2 {
        width: 100%;
        height: 45px;
        line-height: 45px;
        text-align: center;
      }

      .dark .progress {
        margin: 0;
        background-color: #0b2931;
      }
    </style>
  </head>

  <body class="dark">
    <!--加载前进行操作提示，优化用户体验-->
    <div id="mask" class="signmask" onclick="removeMask()"></div>

    <div id="mars3dContainer" class="mars3d-container"></div>

    <!-- 信息 面板 -->
    <div class="infoview rightbottom" style="min-width: 200px; right: 100px">
      <table class="mp_table">
        <tr>
          <td class="nametd">总长度</td>
          <td id="td_alllength"></td>
        </tr>
        <tr>
          <td class="nametd">已漫游长度</td>
          <td id="td_length"></td>
        </tr>
        <tr>
          <td class="nametd">总时长</td>
          <td id="td_alltimes"></td>
        </tr>
        <tr>
          <td class="nametd">已漫游时间</td>
          <td id="td_times"></td>
        </tr>

        <tr>
          <td class="nametd">经度</td>
          <td id="td_jd"></td>
        </tr>
        <tr>
          <td class="nametd">经度</td>
          <td id="td_wd"></td>
        </tr>
        <tr>
          <td class="nametd">漫游高程</td>
          <td id="td_gd"></td>
        </tr>
        <tr>
          <td class="nametd">地面高程</td>
          <td id="td_dmhb"></td>
        </tr>
        <tr id="tr_ldgd">
          <td class="nametd">离地距离</td>
          <td id="td_ldgd"></td>
        </tr>

        <tr>
          <td colspan="2" style="width: 100%; text-align: center">
            <div class="progress">
              <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
            </div>
          </td>
        </tr>
      </table>
    </div>


    <div id="popupContent"  class="marsBlackPanel animation-spaceInDown">
      <div class="marsBlackPanel-text">
        <div style="width: 200px;text-align:left;">
          <div>总 距 离：<span id="lblAllLen"> </span></div>
          <div>总 时 间：<span id="lblAllTime"> </span></div>
          <div>开始时间：<span id="lblStartTime"> </span></div>
          <div>剩余时间：<span id="lblRemainTime"> </span></div>
          <div>剩余距离：<span id="lblRemainLen"> </span></div>
        </div>
      </div>
      <span class="mars3d-popup-close-button closeButton" >×</span>
    </div>



    <script src="./js/common.js"></script>
    <script type="text/javascript">
      "use script"; //开发环境建议开启严格模式

      var map;
      var roamLine;

      function initMap(options) {
        //合并属性参数，可覆盖config.json中的对应配置
        var mapOptions = mars3d.Util.merge(options, {
          control: {
            animation: true, //是否创建动画小器件，左下角仪表
            timeline: true, //是否显示时间线控件
          },
        });

        //创建三维地球场景
        map = new mars3d.Map("mars3dContainer", mapOptions);

        //创建矢量数据图层
        var graphicLayer = new mars3d.layer.GraphicLayer();
        map.addLayer(graphicLayer);

        //该数据可以从 基础项目 飞行漫游功能界面操作后单个路线的 保存JSON
        var flydata = {
          name: "步行路线",
          speed: 40,
          positions: [
            [117.220356, 31.833959, 43.67],
            [117.220361, 31.835111, 44.36],
            [117.213242, 31.835863, 42.31],
            [117.211926, 31.835738, 42.14],
            [117.183103, 31.833906, 47.17],
            [117.183136, 31.833586, 47.39],
            [117.183968, 31.833637, 47.05],
            [117.184038, 31.833134, 47.39],
            [117.184364, 31.833142, 47.26],
            [117.184519, 31.833375, 47.04],
          ],
          model: {
            show: true,
            url: "//data.mars3d.cn/gltf/mars/man/walk.gltf",
            scale: 5,
            minimumPixelSize: 50,
          },
          shadow: [
            {
              type: "circle",
              radius: 10,
              color: "#ffff00",
              opacity: 0.3,
              materialType: mars3d.MaterialType.CircleWave,
              speed: 10,
              count: 3,
              gradient: 0.1,
              show: true,
            },
          ],
          camera: {
            type: "gs",
            radius: 300,
          },
          clockRange: Cesium.ClockRange.CLAMPED, //CLAMPED到达终点后停止
          pauseTime: 0.5,
        };

        roamLine = new mars3d.graphic.RoamLine(flydata);
        graphicLayer.addGraphic(roamLine);

        roamLine.on(mars3d.EventType.endItem, function (event) {
          console.log("已漫游过点：" + event.index, event);
        });
        roamLine.on(mars3d.EventType.end, function (event) {
          console.log("漫游结束", event);
        });

        roamLine.on(mars3d.EventType.change, (event) => {
          //面板显示相关信息
          showRealTimeInfo(event);
        });

        roamLine.bindPopup(document.getElementById("popupContent"), { offsetY: -40 });

        //刷新局部DOM,不影响popup面板的其他控件操作
        roamLine.on(mars3d.EventType.postRender, function (event) {
          let container = event.container; //popup对应的DOM

          var params = roamLine?.info;
          if (!params) {
            return;
          }

          let lblAllLen = container.querySelector("#lblAllLen");
          if (lblAllLen) {
            lblAllLen.innerHTML = haoutil.str.formatLength(roamLine.alllen);
          }

          let lblAllTime = container.querySelector("#lblAllTime");
          if (lblAllTime) {
            lblAllTime.innerHTML = haoutil.str.formatTime(roamLine.alltimes / map.clock.multiplier);
          }

          let lblStartTime = container.querySelector("#lblStartTime");
          if (lblStartTime) {
            lblStartTime.innerHTML = Cesium.JulianDate.toDate(roamLine.startTime).format("yyyy-M-d HH:mm:ss");
          }

          let lblRemainTime = container.querySelector("#lblRemainTime");
          if (lblRemainTime) {
            lblRemainTime.innerHTML = haoutil.str.formatTime((roamLine.alltimes - params.time) / map.clock.multiplier);
          }

          let lblRemainLen = container.querySelector("#lblRemainLen");
          if (lblRemainLen) {
            lblRemainLen.innerHTML = haoutil.str.formatLength(roamLine.alllen - params.len);
          }
        });

        //不贴地时，直接开始
        startFly();

        //贴地时，异步计算完成后开始
        // roamLine.clampToGround(function (e) {//异步计算完成贴地后再启动
        //     //贴地后的路线值为flyLine.positions
        //     startFly()
        // });
      }

      function startFly() {
        //启动漫游
        roamLine.start();

        //显示popup
        roamLine.openPopup();

        //显示基本信息，名称、总长、总时间
        $("#td_alltimes").html(haoutil.str.formatTime(roamLine.alltimes));
        $("#td_alllength").html(haoutil.str.formatLength(roamLine.alllen));
      }

      //显示实时坐标和时间
      function showRealTimeInfo(params) {
        if (params == null) {
          return;
        }
        // console.log(params);
        var val = Math.ceil((params.time * 100) / roamLine.alltimes);
        if (val < 1) {
          val = 1;
        }
        if (val > 100) {
          val = 100;
        }

        $(".progress-bar")
          .css("width", val + "%")
          .attr("aria-valuenow", val)
          .html(val + "%");

        $("#td_jd").html(params.lng);
        $("#td_wd").html(params.lat);
        $("#td_gd").html(haoutil.str.formatLength(params.alt));

        $("#td_times").html(haoutil.str.formatTime(params.time));
        $("#td_length").html(haoutil.str.formatLength(params.len));

        if (params.hbgd) {
          $("#td_dmhb").html(haoutil.str.formatLength(params.hbgd));
        } else {
          $("#td_dmhb").html("未知");
        }

        if (params.ldgd) {
          $("#td_ldgd").html(haoutil.str.formatLength(params.ldgd));
        } else {
          $("#td_ldgd").html("未知");
        }
      }
    </script>
  </body>
</html>
